package cn.tedu.ssm.controller;

import cn.tedu.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
public class IndexController {
    @Autowired
    private UserService service;
    @Autowired
    private UserService userService;
    @ResponseBody
    @RequestMapping("")
    public ModelAndView index(String target) {
        if (StringUtils.isEmpty(target)) {
            target = "welcome";
        }
        ModelAndView view = new ModelAndView("index");
        view.addObject("t", target + ".jsp");
        return view;
    }
    @RequestMapping("userinfo")
    public Map<String, Object> fetchUserInfo(HttpServletRequest req) {
        Long id = (Long) req.getSession().getAttribute("UID");
        return userService.getUserInfo(id);
    }
}